package com.zry.simpleBlog.upload;

import com.zry.simpleBlog.comment.aop.annotations.AuthCheck;
import com.zry.simpleBlog.comment.enums.RoleEnum;
import com.zry.simpleBlog.comment.enums.RespBeanEnum;
import com.zry.simpleBlog.comment.respBean.RespBean;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 */
@RestController
@RequestMapping("/qiniu")
public class QiniuController {
    @Resource
    private QiniuService qiniuService;

    @PostMapping("/upload/avatar")
    @AuthCheck(rank = RoleEnum.USER)
    public RespBean upAvatar(@RequestParam MultipartFile file) throws IOException {
        String url = qiniuService.uploadAvatar(file);
        return RespBean.success(RespBeanEnum.UPLOAD_SUCCESS, url);
    }

}
